#include"tcpInit.h"
#include"logger.h"


int tcpInit(int *sockfd, char* ip, char* port){
    struct sockaddr_in server;
    bzero(&server, sizeof(server));
    server.sin_family = AF_INET;
    server.sin_port = htons(atoi(port));
    server.sin_addr.s_addr = inet_addr(ip);
    // 创建socket
    *sockfd = socket(AF_INET, SOCK_STREAM, 0);
    ERROR_CHECK(*sockfd, -1, "socket");
    LOG_INFO("socket create success", *sockfd);
    //监听
    int ret = bind(*sockfd, (struct sockaddr*)&server, sizeof(server));
    ERROR_CHECK(ret, -1, "bind");
    LOG_INFO("bind success");
    //监听
    ret = listen(*sockfd, 5);
    ERROR_CHECK(ret, -1, "listen");
    LOG_INFO("listen success");


    return 0;
}